package cuit.cx.json;

//import net.sf.json.JSONObject;
import org.json.JSONException;
import org.json.JSONObject;

import cuit.cx.handlemodel.UserInfoHandle;
import cuit.cx.model.Userinfo;

public class LoginHelper {
	
	String jString = "{\"result\":1,\"userInfo\":{\"id\":1,\"createTime\":1332670755574,\"phoneNumber\":\"13551341883\",\"email\":\"945193922@qq.com\",\"name\":\"zhihzi\",\"power\":\"admin\"}}";
	
	public UserInfoHandle doAnaylysis(String data) throws JSONException  {
		
		 /*UserInfoHandle loginHandle = null;
		try {
			JSONObject jsonObject = JSONObject.fromObject(data);
			 loginHandle = (UserInfoHandle) JSONObject.toBean(jsonObject, UserInfoHandle.class);
		} catch (Exception e) {
			
			System.out.println("JSONObject is wrong!!");
			e.printStackTrace();
			
		}
		return loginHandle;*/
		
		JSONObject jsonObject = new JSONObject(data);
		UserInfoHandle userInfoHandle = new UserInfoHandle();
		userInfoHandle.setResult(jsonObject.getInt("result"));
		Userinfo userinfo = new Userinfo();
		JSONObject jsonObject2 = jsonObject.getJSONObject("userInfo");
		userinfo.setId(jsonObject2.getInt("id"));
		userinfo.setCreateTime(jsonObject2.getLong("createTime"));
		userinfo.setPhoneNumber(jsonObject2.getString("phoneNumber"));
		userinfo.setEmail(jsonObject2.getString("email"));
		userinfo.setName(jsonObject2.getString("name"));
		userinfo.setPower(jsonObject2.getString("power"));
		userInfoHandle.setUserinfo(userinfo);
		return userInfoHandle;
		
	}

	

}
